package com.dolphin.apipassenger.controller;

import com.dolphin.apipassenger.request.CheckVerificationCodeDTO;
import com.dolphin.apipassenger.request.SendVerificationCodeDTO;
import com.dolphin.apipassenger.service.VerificationCodeService;
import com.dolphin.common.dto.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class VerificationCodeController {
    @Autowired
    private VerificationCodeService verificationCodeService;
    @GetMapping("verification-code")
    public ResponseResult verificationCode(@Validated @RequestBody SendVerificationCodeDTO verificationCodeDTO) {
        String passengerPhone = verificationCodeDTO.getPassengerPhone();
        System.out.println("手机号：" + passengerPhone);
        return  verificationCodeService.generatorCode(passengerPhone);
    }

    @PostMapping("verification-code-check")
    public ResponseResult checkVerificationCode(@Validated @RequestBody CheckVerificationCodeDTO checkVerificationCodeDTO) {
        String passengerPhone = checkVerificationCodeDTO.getPassengerPhone();
        String verificationCode = checkVerificationCodeDTO.getVerificationCode();
        System.out.println("手机号：" + passengerPhone);
        System.out.println("验证码：" + verificationCode);
        return  verificationCodeService.checkCode(passengerPhone,verificationCode);
    }
}
